<?php
class projectTable extends myDoctrineIndexedTable
{
	/**
	 * Method to get table instance
	 */
	public static function getInstance()
	{
		return Doctrine_Core::getTable('project');
	}
	/**
	 * Get all active projects
	 */
	public function allActiveProjects()
	{
		return $this->createQuery()->where('is_active', 1)->addWhere("type", sfConfig::get('app_project_type'));
	}
	/**
	 * Get new active projects
	 */
	public function newActiveProjects()
	{
		return $this->createQuery()->where('is_active', 1)->addWhere("type", sfConfig::get('app_project_type'))->orderBy("id DESC");
	}
	/**
	 * Get cottage projects 
	 */
	public function cottageActiveProjects()
	{
		return $this->createQuery()->where('is_active', 1)->addWhere('is_cottage', 1)->addWhere("type", sfConfig::get('app_project_type'));
	}
	/**
	 * Get wooden active projects
	 */
	public function woodenActiveProjects()
	{
		return $this->createQuery()->where('is_active', 1)->addWhere('is_wooden', 1)->addWhere("type", sfConfig::get('app_project_type'));
	}
	/**
	 * Get premuim active projects
	 */
	public function premiumActiveProjects()
	{
		return $this->createQuery()->where('is_active', 1)->addWhere('is_premium', 1)->addWhere("type", sfConfig::get('app_project_type'));
	}
	/**
	 * Get multifloor active projects
	 */
	public function multifloorActiveProjects()
	{
		return $this->createQuery()->where('is_active', 1)->addWhere('is_multifloor', 1)->addWhere("type", sfConfig::get('app_project_type'));
	}
	
	/**
	 * Method to get hot project list 
	 * @param int $limit
	 */
	public function getHotProjectList($limit = 5)
	{
		return $this->createQuery()->where("type", sfConfig::get('app_project_type'))->addWhere("is_active", 1)->addWhere("is_hot", 1)->limit($limit)->execute(Doctrine_Core::HYDRATE_RECORD);
	}
	/**
	 * Method to get new projects 
	 * @param int $limit
	 */
	public function getNewProjectList($limit = 5)
	{
		return $this->createQuery()->where("type", sfConfig::get('app_project_type'))->addWhere("is_active", 1)->limit($limit)->orderBy("id DESC")->execute(Doctrine_Core::HYDRATE_RECORD);
	}
	/**
	 * Method to get project example
	 * @param int $id
	 */
	public function getProjectExample($id = null)
	{
		return $this->createQuery()->where("type", sfConfig::get('app_project_type'))->addWhere("is_active", 1)->addWhere("id", $id)->fetchOne(Doctrine_Core::HYDRATE_RECORD);
	}
	/**
	 * Method to get calculation project example
	 * @param int $id
	 */
	public function getCalculationExample($id = null)
	{
		return $this->createQuery()->where("type", sfConfig::get('app_calculation_type'))->addWhere("is_active", 1)->addWhere("id", $id)->fetchOne(Doctrine_Core::HYDRATE_RECORD);
	}
	/**
	 * Method to get list of finished projects
	 * @param int $limit
	 */
	public function getCompletedProjects($limit = 5)
	{
		return $this->createQuery()->where("type", sfConfig::get('app_project_type'))->addWhere("is_active", 1)->limit($limit)->execute(Doctrine_Core::HYDRATE_RECORD);
	}
	/**
	 * Method to get list of calculated projects
	 * @param int $limit
	 */
	public function getCalculatedProjects($limit = 5)
	{
		return $this->createQuery()->where("type", sfConfig::get('app_calculation_type'))->addWhere("is_active", 1)->limit($limit)->execute(Doctrine_Core::HYDRATE_RECORD);
	}
	/**
	 * Method to get list with needed projects
	 */
	public function allActiveCalculation()
	{
		return $this->createQuery()->where('is_active', 1)->addWhere("type", sfConfig::get('app_calculation_type'));
	}
}